package com.ruoyi.web.controller;

import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.SysCourse;
import com.ruoyi.system.service.ISysCourseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCourseNode;
import com.ruoyi.system.service.ISysCourseNodeService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程小结Controller
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@Controller
@RequestMapping("/system/sysCourseNode")
public class SysCourseNodeController extends BaseController
{
    private String prefix = "system/sysCourseNode";

    @Autowired
    private ISysCourseNodeService sysCourseNodeService;

    @Autowired
    private ISysCourseService sysCourseService;

    @RequiresPermissions("system:sysCourseNode:view")
    @GetMapping()
    public String sysCourseNode()
    {
        return prefix + "/sysCourseNode";
    }

    /**
     * 查询课程小结列表
     */
    @RequiresPermissions("system:sysCourseNode:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysCourseNode sysCourseNode)
    {
        startPage();
        List<SysCourseNode> list = sysCourseNodeService.selectSysCourseNodeList(sysCourseNode);
        return getDataTable(list);
    }

    /**
     * 导出课程小结列表
     */
    @RequiresPermissions("system:sysCourseNode:export")
    @Log(title = "课程小结", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysCourseNode sysCourseNode)
    {
        List<SysCourseNode> list = sysCourseNodeService.selectSysCourseNodeList(sysCourseNode);
        ExcelUtil<SysCourseNode> util = new ExcelUtil<SysCourseNode>(SysCourseNode.class);
        return util.exportExcel(list, "课程小结数据");
    }

    /**
     * 新增课程小结
     */
    @RequiresPermissions("system:sysCourseNode:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        SysCourse sysCourse = new SysCourse();
        sysCourse.setCreateBy(ShiroUtils.getLoginName());
        List<SysCourse> sysCourses = sysCourseService.selectSysCourseList(sysCourse);
        mmap.put("sysCourses", sysCourses);
        return prefix + "/add";
    }

    /**
     * 新增保存课程小结
     */
    @RequiresPermissions("system:sysCourseNode:add")
    @Log(title = "课程小结", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysCourseNode sysCourseNode)
    {
        return toAjax(sysCourseNodeService.insertSysCourseNode(sysCourseNode));
    }

    /**
     * 修改课程小结
     */
    @RequiresPermissions("system:sysCourseNode:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysCourseNode sysCourseNode = sysCourseNodeService.selectSysCourseNodeById(id);
        mmap.put("sysCourseNode", sysCourseNode);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程小结
     */
    @RequiresPermissions("system:sysCourseNode:edit")
    @Log(title = "课程小结", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysCourseNode sysCourseNode)
    {
        return toAjax(sysCourseNodeService.updateSysCourseNode(sysCourseNode));
    }

    /**
     * 删除课程小结
     */
    @RequiresPermissions("system:sysCourseNode:remove")
    @Log(title = "课程小结", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysCourseNodeService.deleteSysCourseNodeByIds(ids));
    }
}
